﻿using System;
using System.Runtime.Serialization;

using zijian666.Abstractions;

namespace zijian666.Translator;

/// <summary>
/// <seealso cref="IObjectReference"/> 翻译器
/// </summary>
public class ObjectReferenceTranslator : ITranslator
{

    /// <inheritdoc />
    public bool TryTranslate(IConvertContext context, object? input, out object? translated)
    {
        if (input is IObjectReference reference)
        {
            translated = reference.GetRealObject(default);
            return !ReferenceEquals(translated, reference);
        }
        translated = null;
        return false;
    }
}
